﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Database.Models
{
    [Table("Doi")]
    public class Doi : BaseModel
    {
        public Doi()
        {
            CanBos = new HashSet<CanBo>();
        }

        public int Id { get; set; }

        [Required]
        [MaxLength(255)]
        public string TenDoi { get; set; }

        [MaxLength(2000)]
        public string DienGiai { get; set; }

        public virtual Phong Phong { get; set; }

        public virtual ICollection<CanBo> CanBos { get; set; }

        [NotMapped]
        public virtual string TenPhong
        {
            get
            {
                if (Phong != null)
                {
                    return Phong.TenPhong;
                }
                return string.Empty;
            }
        }

        [NotMapped]
        public virtual string DanhSachCanBo
        {
            get
            {
                string content = string.Empty;
                if (CanBos != null && CanBos.Count > 0)
                {
                    foreach (var canBo in CanBos)
                    {
                        if (string.IsNullOrEmpty(content))
                        {
                            content = canBo.HoTen;
                        }
                        else
                        {
                            content = string.Concat(content, Environment.NewLine, canBo.HoTen);
                        }
                    }
                }
                return content;
            }
        }
    }
}